package com.libraryApp.controller;

import com.libraryApp.appCommon.Constants;
import com.libraryApp.appUtil.Result;
import com.libraryApp.appUtil.ResultGenerator;
import com.libraryApp.appUtil.TokenToUser;
import com.libraryApp.appUtil.page.PageQueryUtil;
import com.libraryApp.appUtil.page.PageResult;
import com.libraryApp.appVo.AppUserBorrowVo;
import com.libraryApp.entity.UserDo;
import com.libraryApp.service.AppBorrowService;
import com.libraryManage.commons.utils.ResponseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @CreateDate 2021-03-08
 * @Author yufang
 */
@Api(tags={"用户借阅接口"})
@RestController
@CrossOrigin
@RequestMapping("/app/user/borrow")
public class AppBorrowController {

    @Autowired
    AppBorrowService appBorrowService;

    @ApiOperation("查询借阅记录 0-》未归还 1-》按时归还 2-》超时归还")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/list" , method = RequestMethod.GET)
    public ResponseEntity<List<AppUserBorrowVo>> borrowList(@RequestParam(required = false)Integer pageNumber,
                                                            @RequestParam(required = false) Integer status,
                                                            @TokenToUser UserDo userDo){
        Map params = new HashMap(4);
        if (pageNumber == null || pageNumber < 1) {
            pageNumber = 1;
        }
        return appBorrowService.borrowList(userDo.getUserId(),pageNumber,status);
    }

}
